package com.itheima.reggie.exception;

import com.itheima.reggie.common.CustomException;
import com.itheima.reggie.common.ResultInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    //非预期异常处理
    @ExceptionHandler(Exception.class)
    public ResultInfo exceptionHandler(Exception ex){
        log.error(ex.getMessage());
        return ResultInfo.error("对不起,网络问题,请稍后再试");
    }

    //预期异常处理
    @ExceptionHandler(CustomException.class)
    public ResultInfo customExceptionHandler(CustomException ce){
        log.error(ce.getMessage());
        return ResultInfo.error(ce.getMessage());
    }
}
